const path = require('path');
const fs = require('fs');
const BingAudio = require('./BingAudio');

// 创建音频分类目录
const dir = [
  path.join(__dirname, 'mp3'),
  path.join(__dirname, 'mp3', 'en'),
  path.join(__dirname, 'mp3', 'zh')
];
for (let i = 0; i < dir.length; i++) {
  const element = dir[i];
  if (!fs.existsSync(element)) {
    fs.mkdirSync(element);
  }
}


const item = ['六级词汇', '四级词汇', '小学3-6年级', '托福词汇', '考研', '雅思词汇'];
for (const v of item) {
  const jsonPath = path.join(__dirname, 'data', v) + '.json';
  const url = 'https://www.bing.com/tspeak?&format=audio%2Fmp3&language=en-IN&IG=8268317E31204A93B36CC0C65420511A&IID=translator.5038.3&options=female&text=';
  const urlZh = 'https://www.bing.com/tspeak?&format=audio%2Fmp3&language=zh-CN&IG=8268317E31204A93B36CC0C65420511A&IID=translator.5038.5&options=female&text=';
  const audioDir = path.join(__dirname, 'mp3', 'en', v);
  if (!fs.existsSync(audioDir)) {
    fs.mkdirSync(audioDir);
  }
  const audioDirZh = path.join(__dirname, 'mp3', 'zh', v);
  if (!fs.existsSync(audioDirZh)) {
    fs.mkdirSync(audioDirZh);
  }

  const audio = new BingAudio(require(jsonPath), url, audioDir);
  audio.crawl();

  const audioZh = new BingAudio(require(jsonPath), urlZh, audioDirZh);
  audioZh.crawlZh();
}